// mircoApp/cultivateCourse/chargeOff/index.js
const app = getApp();
const skinBehavior = require('../../../utils/themeSkin/skinBehavior');

Page({
  behaviors: [skinBehavior],
  /**
   * 页面的初始数据
   */
  data: {
    status: false,
    imgPath: app.globalData.imgPath,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    if (options.scene) {
      let scene = decodeURIComponent(options.scene);
      if (scene) {
        var info_arr = [];
        info_arr = scene.split(",");
        for (let i = 0; i < info_arr.length; i++) {
          let chil_arr = [];
          chil_arr = info_arr[i].split("=");
          if (chil_arr[0] == "enroll_id") {
            this.setData({
              id:chil_arr[1],
            });
          }
        }
      }
    }
    this.setData({
      status: false
    })
    this.getData();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  subminChargeOff() {
    app._postNetWork({
      url: app.getNetAddresss("plugin.cultivate-course.frontend.controllers.course.clerk.clerk"),
      data: {
        id: this.options.id || this.data.id
      },
      success: (resdata) => {
        var res = resdata.data;
        if (res.result == 1) {
          app.tips("核销成功")
          setTimeout(() => {
            // 核销成功去培训课程管理页面
            wx.redirectTo({
              url: '/mircoApp/cultivateCourse/manage/index/index?id=2',
            })
          }, 1000);
        } else {
          app.tips(res.msg);
        }
      }
    });
  },
  getData() {
    app._postNetWork({
      url: app.getNetAddresss("plugin.cultivate-course.frontend.controllers.course.clerk.detail"),
      data: {
        id: this.options.id || this.data.id
      },
      success: (resdata) => {
        var res = resdata.data;
        if (res.result == 1) {
          this.setData({
            status: true,
            info: res.data
          })
        } else {
          this.setData({
            status: false,
            failTxt: res.msg
          })
          app.tips(res.msg);
        }
      }
    });
  }
})